package com.b.service.impl;

import com.b.repository.ProductImageRepository;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import com.b.domain.ProductImage;
import com.b.dao.ProductImageMapper;
import com.b.service.ProductImageService;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
public class ProductImageServiceImpl implements ProductImageService{

    @Resource
    private ProductImageMapper productImageMapper;
    @Resource
    private ProductImageRepository productImageRepository ;

    @Override
    @Transactional
    public boolean deleteByPrimaryKey(Integer id) {
        try {
            productImageMapper.deleteByPrimaryKey(id);
            productImageRepository.deleteById(id);
            return true;
        } catch (Exception e) {
            return false;
        }

    }

    @Override
    @Transactional
    public boolean insert(ProductImage record) {
        try {
            productImageMapper.insert(record);
            productImageRepository.save(record);
            return true;
        } catch (Exception e) {
            return false;
        }

    }

    @Override
    public int insertSelective(ProductImage record) {
        return productImageMapper.insertSelective(record);
    }

    @Override
    public ProductImage selectByPrimaryKey(Integer id) {
        return productImageMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(ProductImage record) {
        return productImageMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(ProductImage record) {
        return productImageMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<ProductImage> getAll() {
        return productImageMapper.getAll();
    }

    @Override
    public List<ProductImage> selectByProductId(Integer productId) {
        return productImageRepository.searchProductImageByProductId(productId);
    }
}
